<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<link rel="stylesheet" href="../../../static/manage/common/bootstrap/css/bootstrap.min.css" />
		<script type="text/javascript" src="../../../static/manage/common/js/jquery-3.2.0.min.js"></script>
		<script type="text/javascript" src="../../../static/manage/common/bootstrap/js/bootstrap.min.js"></script>

		<link rel="stylesheet" href="../../../static/manage/common/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script type="text/javascript" src="../../../static/manage/common/bootstarp-table-1.11.1/bootstrap-table.min.js"></script>
		<script type="text/javascript" src="../../../static/manage/common/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js"></script>

		<script type="text/javascript">
			
			$(function() {
				//	alert("json");
				//1.初始化Table
				var oTable = new TableInit();
				oTable.Init();
				var message = document.getElementById("message").value;
				if(message != null && message != "") {
					alert(message);
				}
			});

			var TableInit = function() {
				var oTableInit = new Object();
				//初始化Table
				oTableInit.Init = function() {

					$('#t').bootstrapTable({

						method: 'get',
						contentType: "application/x-www-form-urlencoded",
						url: "/nursetype/nurse", //请求后台的URL（*）
						striped: true, //是否显示行间隔色
						locale: 'zh-CN', //中文支持
						pagination: true, //是否开启分页（*）
						pageNumber: 1, //初始化加载第一页，默认第一页
						pageSize: 9, //每页的记录行数（*）
						pageList: [5, 7, 9], //可供选择的每页的行数（*） 
						sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
						showRefresh: true, //刷新按钮
						queryParams: oTableInit.queryParams, //传递参数（*）
						strictSearch: true,
						showColumns: true, //是否显示所有的列
						minimumCountColumns: 2, //最少允许的列数
						clickToSelect: true, //是否启用点击选中行

						columns: [{
								field: 'type_id',
								title: '类型编号',
								align: 'center'
						},{
								field: 'type_name',
								title: '类型名称',
								align: 'center'
						},{
								field: 'sort_no',
								title: '排序号',
								align: 'center'
							},{
								field: 'type_remark',
								title: '备注',
								align: 'center'
							},{
								field: 'modify_time',
								title: '修改时间',
								align: 'center',
								formatter: function (value, row, index) {
									return RiQi(value);
								}
							},{
								title: '操作', 
								align: 'center',
								valign: 'middle',
								formatter:function(value,row,index){
									return "<button class='btn btn-success' data-toggle='modal' data-target='#myModal2' onclick='update("+row.type_id+")'>修改</button>&nbsp;&nbsp;<button class='btn btn-danger'onclick='del("+row.type_id+")'>删除</button>"
								}
							}
						]

					});

				};
				//得到查询的参数
				oTableInit.queryParams = function(params) {
					var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
						limit: params.limit, //页面大小
						offset: params.offset, //偏移量
						type_name: $("#type_name").val()
					};
					return temp;
				};
				return oTableInit;
			};
			
			//模糊查询
			function select(){
				$("#t").bootstrapTable("refresh")
			}
			
			//时间戳转时间
		    function RiQi(sj){
		        var now = new Date(sj);
		        var   year=now.getFullYear();
		        var   month=now.getMonth()+1;
		        var   date=now.getDate();
		        var   hour=now.getHours();
		        var   minute=now.getMinutes();
		        var   second=now.getSeconds();
		        return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second; 
		    }
		    
		    //重置
		    function row(){
		    	$("#type_name").val("");
		    }
		    
		    //添加方法
			function add () {
				$.ajax({
					type:"post",
					url:"/nursetype/add",
					data:$("#fo").serialize(),
					success:function(data){
						$("#t").bootstrapTable("refresh")
						$("#myModal").modal("hide")
					}
				});
			}
			
			//删除
			function del (type_id) {
				alert(type_id)
				$.ajax({
					type:"post",
					url:"/nursetype/del/"+type_id,
					success:function () {
						$('#t').bootstrapTable("refresh")
						$("#myModal").modal("show")
					}
				});
			}
			
			//修改
			function update (type_id) {
				$.ajax({
					type:"post",
					url:"/nursetype/update/"+type_id,
					success:function(msg){
						alert(msg)
						$("#type_id2").val(msg.type_id);
						$("#type_name2").val(msg.type_name);
						$("#type_remark2").val(msg.type_remark);
						$("#sort_no2").val(msg.sort_no);
						$("#modify_time2").val(msg.modify_time);
						$("#t").bootstrapTable("refresh")
						$("#myModal2").modal("show");
					}
				});
			}
			function up(type_id) {
				$.ajax({
					type:"post",
					url:"/nursetype/up/",
					data:$("#for").serialize(),
					success:function(msg){
						alert(msg)
						$("#myModal2").modal("show");
					}
				});
			}
		</script>
	</head>

	<body>
		<!--系统管理--用户管理界面模糊查询-->
		<form class="form-inline">
			<div class="form-group">
				<div class="col-sm-10">
					<input type="text" class="form-control" id="type_name" placeholder="请输入类型名称">
				</div>
			</div>
			<button type="button" class='btn btn-success' onclick="select()">查询</button>
			<button type="button" class="btn btn-primary" onclick="row()">重置</button>
		</form>
		<br>
		<button id="ad" data-toggle="modal" data-target="#myModal" type="button" class="btn btn-info">新增</button>
		
		<br><br>
		<table id="t">
			<div class="inline">
				
			</div>

		</table>
		
		<!--添加的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">新增</h4>
					</div>
					<div class="modal-body">
						
						<!--添加form表单-->
						<form class="form-horizontal" id="fo">
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputName">类型编号</label>
									<input type="text" class="form-control" id="type_id" name="type_id" placeholder="请输入类型编号">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputName">分类名称</label>
									<input type="text" class="form-control" id="type_name" name="type_name" placeholder="请输入分类名称">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputRemark">备注</label>
									<textarea class="form-control" rows="3" id="type_remark" name="type_remark" placeholder="请输入备注"></textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputSort_no">排序</label>
									<input type="text" class="form-control" id="sort_no" name="sort_no" placeholder="请输入排序编号">
								</div>
							</div>
							<!--<div class="form-group">
								<label for="modifytime">更新时间</label>
								<input type="datetime-local" class="form-control" id="modify_time" name="modify_time">
							</div>-->
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" id="add" onclick="add()" class="btn btn-primary" data-dismiss="modal">添加</button>
					</div>
				</div>
			</div>
		</div>
		
		<!--修改的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">修改</h4>
					</div>
					<div class="modal-body">
						
						<!--修改form表单-->
						<form class="form-horizontal" id="for">
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputName">类型编号</label>
									<input type="text" class="form-control" id="type_id2" name="type_id" placeholder="请输入类型编号">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputName">分类名称</label>
									<input type="text" class="form-control" id="type_name2" name="type_name" placeholder="请输入分类名称">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputRemark">备注</label>
									<textarea class="form-control" rows="3" id="type_remark2" name="type_remark" placeholder="请输入备注"></textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-10">
									<label for="exampleInputSort_no">排序</label>
									<input type="text" class="form-control" id="sort_no2" name="sort_no" placeholder="请输入排序编号">
								</div>
							</div>
							<!--<div class="form-group">
								<label for="modifytime">更新时间</label>
								<input type="datetime-local" class="form-control" id="modify_time" name="modify_time">
							</div>-->
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" id="update" onclick="up()" class="btn btn-primary" data-dismiss="modal">修改</button>
					</div>
				</div>
			</div>
		</div>
	</body>

</html>